package cn.txm.product.Controller;

import cn.txm.basic.util.PageList;
import cn.txm.order.domain.OrderAddress;
import cn.txm.order.service.IOrderAddressService;
import cn.txm.pet.domain.Pet;
import cn.txm.pet.query.PetQuery;
import cn.txm.pet.service.IPetService;
import cn.txm.product.domain.Product;
import cn.txm.product.query.ProductQuery;
import cn.txm.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 前台系统加载数据：不被登录拦截
 * @author Administrator
 * @version 1.0
 * @date 2021/1/18 10:43
 */
@RestController
@RequestMapping("/front")
public class FrontController {
    @Autowired
    private IProductService productService;
    @Autowired
    private IPetService petService;

    @Autowired
    private IOrderAddressService orderAddressService;
    /**
     * 前台：加载商品服务列表，支持分页查询+高级查询
     * @param productQuery
     * @return
     */
    @PostMapping("/product")
    public PageList<Product> pageList(@RequestBody ProductQuery productQuery){
        return productService.queryPage(productQuery);
    }

    /**
     * 前台：通过id查询商品信息包含商品详情信息（点击查看商品详情）
     * @param id
     * @return
     */
    @GetMapping("/product/{id}")
    public Product getProductById(@PathVariable("id")Long id){
        return productService.getById(id);
    }

    /**
     * 前台：加载宠物列表，支持分页查询+高级查询
     * @param petQuery
     * @return
     */
    @PostMapping("pet")
    public PageList<Pet> pageList(@RequestBody PetQuery petQuery){
        return petService.queryPage(petQuery);
    }

    /**
     * 前台：通过id查询宠物信息包含宠物详情信息（点击查看宠物详情）
     * @param id
     * @return
     */
    @GetMapping("/pet/{id}")
    public Pet getById(@PathVariable("id")Long id){
        return petService.getById(id);
    }

    /**
     * 前台：通过orderSn查询订单地址
     * @param orderSn
     * @return
     */
    @GetMapping("/orderAddress/{orderSn}")
    public OrderAddress loadOrderAddressByOrderSn(@PathVariable("orderSn") String orderSn){
        return orderAddressService.loadOrderAddressByOrderSn(orderSn);
    }
}
